﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using Shove.Web.UI;

public partial class UserControls_UserselfGood : UCBase 
{
    public UserControls_UserselfGood()
    {
        Name = "会员推荐商品";
        
        swpas = new ShoveWebPartAttribute[5];

        swpas[0] = new ShoveWebPartAttribute_Int("推荐商品图片宽度", "1,400", 110, "推荐商品图片宽度");
        swpas[1] = new ShoveWebPartAttribute_Int("推荐商品图片高度", "1,400", 100, "推荐商品图片高度");
        swpas[2] = new ShoveWebPartAttribute_Int("控件宽度", "1,1000", 546, "控件宽度");
        swpas[3] = new ShoveWebPartAttribute_Int("控件高度", "1,1000", 150, "控件高度");
        swpas[4] = new ShoveWebPartAttribute_Int("控件中每行显示的个数", "1,10", 4, "控件中每行显示产品的个数");

        //swpas[7] = new ShoveWebPartAttribute_Text("商品名CSS样式", "", "pro_name", "商品名CSS样式");
        //swpas[8] = new ShoveWebPartAttribute_Text("市场价CSS样式", "", "market_price", "市场价CSS样式");
        //swpas[9] = new ShoveWebPartAttribute_Text("会员价CSS样式", "", "user_price", "会员价CSS样式");
        //swpas[10] = new ShoveWebPartAttribute_Text("立即节省CSS样式", "", "vip_price", "立即节省CSS样式");
        //swpas[11] = new ShoveWebPartAttribute_Image("新品上架图片", "", "images/UserControls/GoodSpecial.bmp", "新品上架图片");
        //swpas[12] = new ShoveWebPartAttribute_Image("新品更多图片", "", "images/UserControls/GoodMore.bmp", "新品更多图片");
        //swpas[13] = new ShoveWebPartAttribute_Color("控件边框颜色", "#cccccc", "控件边框颜色");
    }

    private void Initlayout()
    {
        tabctr.Width = swpAttributes[2];
        tabctr.Height = swpAttributes[3];    

        dlFavorable.RepeatColumns = Shove._Convert.StrToInt(swpAttributes[4], 4);
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        Initlayout();
        BindData();
    }

    private void BindData()
    {
        long ShopID =_Site.ID;
        DataTable dt = null;

        dt = new DAL.Views.V_Site_GoodShopStock().Open("top 4 * ", "isOnSale = 1 and ShopID=" + _Site.ID, "");

        dlFavorable.DataSource = dt;
        dlFavorable.DataBind();
    }
    protected void dlFavorable_ItemDataBound(object sender, DataListItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
        {
            try
            {
                Image img = (Image)e.Item.FindControl("imgGoodPic");
                img.ImageUrl = "../UpFile/Goods/" + img.ImageUrl;
                img.Width = new Unit(swpAttributes[0]);
                img.Height = new Unit(swpAttributes[1]);
            }
            catch { }

            //HtmlTableCell tdname = (HtmlTableCell)e.Item.FindControl("tdname");
            //tdname.Height = swpAttributes[6];
            //tdname.Attributes.Add("class", swpAttributes[7]);

            //HtmlTableCell tdmark = (HtmlTableCell)e.Item.FindControl("tdmark");
            //tdmark.Height = swpAttributes[6];
            //tdmark.Attributes.Add("class", swpAttributes[8]);

            //HtmlTableCell tduser = (HtmlTableCell)e.Item.FindControl("tduser");
            //tduser.Height = swpAttributes[6];
            //tduser.Attributes.Add("class", swpAttributes[9]);

            //HtmlTableCell tdvip = (HtmlTableCell)e.Item.FindControl("tdvip");
            //tdvip.Height = swpAttributes[6];
            //tdvip.Attributes.Add("class", swpAttributes[10]);
        }
    }
}
